package org.pay.union.enums.debitcredit;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import org.pay.union.enums.DebitCredit;

import java.io.Serializable;

/**
 * 微信借贷分离标识
 */
@Getter
public enum UnionPayCreditEnum implements Serializable, DebitCredit {
    DEBIT_CARD("01", "借记卡", null), CREDIT_CARD("02", "信用卡", null),
    ;
    private String code;
    private String type;
    private String bank;

    UnionPayCreditEnum(String code, String type, String bank) {
        this.code = code;
        this.type = type;
        this.bank = bank;
    }

    public static UnionPayCreditEnum codeOf(String code) {
        for (UnionPayCreditEnum jd : UnionPayCreditEnum.values()) {
            if (jd.getCode().equals(code)) {
                return jd;
            }
        }
        return null;
    }

    public String getBank() {
        return StrUtil.isBlank(bank) ? type : bank;
    }

}
